package com.xuecheng.content.interfaces.web;

import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.application.service.CourseBaseApplication;
import com.xuecheng.content.application.vo.req.CourseBaseUpdateCmd;
import com.xuecheng.content.domain.model.dto.CourseBaseDto;
import com.xuecheng.content.application.vo.req.CourseBaseCreateCmd;
import com.xuecheng.content.application.vo.req.CourseBaseQry;
import com.xuecheng.content.infrastructure.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-07-25  19:50
 */
@Api(value = "课程信息编辑接口",tags = "课程信息编辑接口")
@RestController
public class CourseBaseInfoApi {

    @Autowired
    private CourseBaseApplication courseBaseApplication;

    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBaseDto> list(PageParams pageParams,
                                          @RequestBody(required = false) CourseBaseQry courseBaseQry){
        return courseBaseApplication.queryCourseBaseList(pageParams, courseBaseQry);
    }

    @ApiOperation("新增课程基础信息")
    @PostMapping("/course")
    public CourseBaseDto createCourseBase(@Validated @RequestBody CourseBaseCreateCmd courseBaseCreateCmd){
        Long companyId = 1232141425L;
        return courseBaseApplication.createCourseBase(companyId, courseBaseCreateCmd);
    }

    @ApiOperation("根据课程id查询课程基础信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseDto getCourseBaseById(@PathVariable Long courseId){
        return courseBaseApplication.queryCourseBaseMarket(courseId);
    }

    @ApiOperation("修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseDto modifyCourseBase(@Validated @RequestBody CourseBaseUpdateCmd editCourseDto){
        Long companyId = 1232141425L;
        return courseBaseApplication.updateCourseBase(companyId, editCourseDto);
    }

    @ApiOperation("预览课程")
    @GetMapping("/coursepreview/{courseId}")
    public ModelAndView previewCourse(@PathVariable("courseId") Long courseId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("course_template");
        modelAndView.addObject("model", courseBaseApplication.queryCourseBasePreview(courseId));
        return modelAndView;
    }

    @ApiOperation("课程提交审核")
    @PostMapping("/courseaudit/commit/{courseId}")
    public void commitAudit(@PathVariable("courseId") Long courseId){
        Long companyId = 1232141425L;
        courseBaseApplication.commitAudit(courseId, companyId);
    }
}
